<?php
/**
 * Created by PhpStorm.
 * User: fyk
 * Date: 2019/12/4
 * Time: 11:19
 */
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Properties_m extends MY_Model
{

    const TBL        = 'properties';
    const UNIQUE_KEY = 'create_time';

    function __construct()
    {
        parent::__construct();
    }

    public function count_articles()
    {
        $this->db->select('*');
        $this->db->from('properties');
        $total = $this->db->count_all_results();
        return $total;
    }

    //翻页及搜索
    public function get_article_list($start, $limit, $order = "id", $sc = "ASC")
    {
        $this->db->select('*');
        $this->db->from('properties');
        $this->db->order_by($order, $sc);
        $this->db->limit($limit, $start);
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        }
    }

    public function get_limit_list($num, $field = "*")
    {
        $this->db->select($field);
        $this->db->from('properties');
        $this->db->order_by("id", 'desc');
        $this->db->limit($num);
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result_array();
        }
    }

    public function select_by($where = "", $limit = "", $start = 0, $field = "*", $orderBy = "id", $sort = "desc")
    {
        if ($where) {
            $this->db->where($where);
        }
        if ($limit) {
            $this->db->limit($limit, $start);
        }
        $this->db->select($field);
        $this->db->order_by($orderBy, $sort);
        $query = $this->db->get("properties");
        $data  = $query->result_array();
        $query->free_result();
        return $data;
    }
}
